/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2012
 */

package com.tech15.pub.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.File;
import java.util.*;

import javacommon.base.*;
import javacommon.util.*;

import cn.org.rapid_framework.util.*;
import cn.org.rapid_framework.web.util.*;
import cn.org.rapid_framework.page.*;
import cn.org.rapid_framework.page.impl.*;

import com.tech15.core.model.Attach;
import com.tech15.core.service.AttachManager;
import com.tech15.pub.model.*;
import com.tech15.pub.dao.*;
import com.tech15.pub.service.*;
import com.tech15.pub.vo.query.*;

/**
 * @author 胡作正 email:zuozhenghu@sina.com
 * @version 1.0
 * @since 1.0
 */

@Service
@Transactional
public class PubCcsqManager extends BaseManager<PubCcsq,java.lang.String>{

	private PubCcsqDao pubCcsqDao;
	private AttachManager attachManager;
	private MsgTipsDao msgTipsDao;
	
	public void setMsgTipsDao(MsgTipsDao dao) {
		this.msgTipsDao = dao;
	}
	
	public void setAttachManager(AttachManager attachManager) {
		this.attachManager = attachManager;
	}
	public void setPubCcsqDao(PubCcsqDao dao) {
		this.pubCcsqDao = dao;
	}
	public EntityDao getEntityDao() {
		return this.pubCcsqDao;
	}
	
	@Transactional(readOnly=true)
	public Page findPage(PubCcsqQuery query) {
		return pubCcsqDao.findPage(query);
	}
	
	@Transactional(readOnly=true)
	public Page findByPageRequest(PageRequest pr) {
		return pubCcsqDao.findByPageRequest(pr);
	}
	
	@Transactional(readOnly=true)
	public PubCcsq getById(String id){
		PubCcsq ccsq = pubCcsqDao.getById(id);
		
		List<Attach> attach = attachManager.findByTableNameAndId(Notes.TABLE_PUB_CCSQ, ""+id);
		ccsq.setAttach(attach);
		return ccsq;
	}
	
	public Page myTask(PubCcsqQuery query) {
		return pubCcsqDao.myTask(query);
	}
	public void sh(PubCcsq pubCcsq) {
		pubCcsq.setShsj(DateTools.getCurrentTime());
		pubCcsqDao.update(pubCcsq);
	}
	public void updateCc(PubCcsq pubCcsq,String realpath, List<File> attachFile, List<String> attachFileFileName, List<String> attachFileContentType) {
		if(attachFile != null){
			attachManager.saveAttachs(realpath, pubCcsq.getUserid(), Notes.TABLE_PUB_CCSQ, ""+pubCcsq.getId(), attachFile, attachFileFileName, attachFileContentType);
			pubCcsq.setZt(1);
			pubCcsqDao.update(pubCcsq);
		}
	}
	public void saveCc(PubCcsq pubCcsq) {
		pubCcsq.setTjsj(DateTools.getCurrentTime());
		pubCcsq.setZt(0);
		pubCcsqDao.save(pubCcsq);
		pubCcsqDao.flush();
		
//		保存任务提示
		MsgTips tips = new MsgTips();
		tips.setBt(pubCcsq.getYgxm()+"出差申请");
		tips.setContent(pubCcsq.getCcly());
		tips.setTablename(Notes.TABLE_PUB_CCSQ);
		tips.setTableid(pubCcsq.getId()+"");
		tips.setZt(0);
		tips.setXxsj(DateTools.getCurrentTime());
		tips.setUserid(pubCcsq.getSpr());
		tips.setUrl(Notes.pubCcsqUrl+"id="+pubCcsq.getId());
		msgTipsDao.save(tips);
	}
	
	public Integer getTaskCount(Long userid){
		return pubCcsqDao.getTaskCount(userid);
	}
	
}
